package me.yangteng.zhihudaily.component;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivityBase;
import me.imid.swipebacklayout.lib.app.SwipeBackActivityHelper;

/**
 * Created by MorenYang on 2017/12/20.
 * https://github.com/ikew0ng/SwipeBackLayout/
 */

public abstract class SwipeBackActivity extends Activity implements SwipeBackActivityBase {

  private SwipeBackActivityHelper swipeBackActivityHelper;

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    swipeBackActivityHelper = new SwipeBackActivityHelper(this);
    swipeBackActivityHelper.onActivityCreate();
  }

  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    swipeBackActivityHelper.onPostCreate();
  }

  @Override
  public View findViewById(int id) {
    View v = super.findViewById(id);
    if (v == null && swipeBackActivityHelper != null)
      return swipeBackActivityHelper.findViewById(id);
    return v;
  }

  @Override
  public SwipeBackLayout getSwipeBackLayout() {
    return swipeBackActivityHelper.getSwipeBackLayout();
  }

  @Override
  public void setSwipeBackEnable(boolean enable) {
    getSwipeBackLayout().setEnableGesture(enable);
  }

  @Override
  public void scrollToFinishActivity() {
    me.imid.swipebacklayout.lib.Utils.convertActivityToTranslucent(this);
    getSwipeBackLayout().scrollToFinishActivity();
  }

}
